<template>
  <el-form :model="form" label-position="top">
    <el-form-item label="标题">
      <el-input v-model="form.title" @change="onConfigChange" />
    </el-form-item>
    <el-form-item label="提示语">
      <el-input v-model="form.tips" @change="onConfigChange" type="textarea" />
    </el-form-item>
    <el-form-item label="是否必填">
      <el-switch v-model="form.required" @change="onConfigChange" />
    </el-form-item>
    <el-form-item label="表单ID">
      <el-input v-model="form.key" @change="onConfigChange" />
    </el-form-item>
  </el-form>
</template>

<script setup lang="ts">
const { updateFormItem } = inject<{ updateFormItem: (id: string, config: any) => void }>('forms', {
  updateFormItem: () => {}
})
const props = defineProps<{
  id: string
  tdId: string
  formType: string
  config: any
}>()
let form = reactive({
  title: '',
  tips: '', // 提示语
  required: false, // 是否必填
  key: '', // 表单项key值
})
onMounted(() => {
  form = Object.assign(form, props.config)
})
watch(props, () => {
  form = Object.assign(form, props.config)
})
const onConfigChange = () => {
  updateFormItem(props.id, form)
}
</script>
